home *** CD-ROM | disk | FTP | other *** search
-
- More Mode Conversions
- Robin Newman
-
-
- Spurred on by last monthUs Archive, Robin has sent us two machine
- code utilities and two BASIC programs which will convert mode 7
- screens either to mode 4 (monochrome) or mode 9. The main purpose
- of these is to allow a suitable graphics screen dump to be used
- to print out these screens, but they can also just be used to
- produce the converted screen. The starting point was a BASIC
- program called Simul8 first broadcast in 1984 on CEEFAX to enable
- users to dump CEEFAX pages to a printer, by converting MODE 7
- screens to MODE 4. First of all I converted this from lots of
- IFUs and GOTOUs to using CASE and multi-line IF THEN ELSE
- statements. Also, I developed one or two other routines which
- allowed the original MODE 7 screen to be saved and then restored
- after the conversion/dump process was completed. At this stage I
- also realised that the same program could easily be modified to
- convert MODE 7 to MODE 9.
-
- The next stage was to try and rewrite the BASIC progam in ARM
- assembler. This was done partly as an exercise, but also to
- produce a much more convenient utility which could be called from
- any BASIC program where it was desired to dump a mode 7 screen.
- The format decided upon was to have a command *M7M4 (or *M7M9)
- followed by a parameter which detailed the dump to be used: e.g.
- *M7M4 HardcopyFX, or *M7M4 Mydump. The utility checks the
- screenmode when it is called and if it is already a graphics mode
- merely passes the command onto the dump routine. If however the
- screen mode is 7, the utility first saves the existing mode 7
- screen and current character set before redefining the character
- set and converting the screen and calling the dump routine. When
- the dump has completed, control is passed back to the utility
- which restores the original screen and character set before
- exiting. Thus the process is completely transparent to the
- calling program. In addition, it is possible to save converted
- screens merely by changing the command line to *M7M4 SCREENSAVE
- myscreen, or even *M7M9 FASTSAVE myscreen if you have the FAST
- screen load/save module installed. To facilitate testing, I have
- also included a dummy RdumpS called WAIT (with source code
- WAITsrc) which merely waits for a key to be pressed before
- returning.
-
- Machine Code Technicalities
-
- The source code for M7M4 on the program disc is heavily
- commented, so readers should be able to follow how the code fits
- in with the original BASIC progam. However there are perhaps one
- or two features which may be of interest to those trying to write
- there own transient utilities. First, the object code is set to
- type &FFC in line 190, which indicates to the operating system
- that it is a transient which should be loaded and run in the RMA
- area. This gives one potential problem. There must be sufficient
- free room in the RMA for the program to work. If you have not
- loaded any other modules this is likely to be the case. However
- if you QUIT to the supervisor mode and then load in a module,
- when you restart BASIC it appears to claim back any remaining RMA
- space. The cure appears to be to type *M7M4 WAIT from the
- no-language environment before starting up BASIC. This claims the
- required space which is released on exit, but NOT reclaimed by
- BASIC when it starts up unless you issue an RMTidy command first.
-
- The other main problem with transients is that there is a bug in
- the stack pointer which is passed to the transient on entry. It
- is not positioned correctly and calls to OS routines from within
- the transient can result in corruption of the stack. The solution
- is to subtract around 30 bytes from the stack pointer passed in
- R13 before you start using it. Other details on transient
- operation are given on page 353 of the PRM. A workspace of 1024
- bytes is automatically allocated on entry (pointed to by R12).
- However, in this case rather more than that is required to store
- the original character set and the mode 7 screen. Thus, a call is
- made to XOS_Module to claim extra space in which to store these.
- Notice the use of the X prefix here and in various other OS calls
- within the utility. This ensures that if an error occurs within
- the call that control is retained by the user. The error is
- signified by the V bit being set in the processor status flags.
- Appropriate error action can then be taken. In fact two error
- messages are used in the utility. (lines 2300, 2310). These error
- blocks consist of an error number, followed by the error string
- and terminated with a 0 byte. For lack of any allocated error
- numbers, I have used 0 in each case. R0 is set to point to the
- error number and the control is passed to the calling program
- with the V status flag being set on exit (lines 510-520). In this
- way the user can deal with errors using standard ON ERROR
- techniques. Any errors occuring within the DUMP routine are
- similarly passed back to the calling program to deal with (e.g.
- timeout if the printer is offline). Here the procedure is
- slightly trickier, because we first have to ensure that the
- original mode 7 screen and character set are restored and that
- the RMA workspace claimed is released. The solution is to save
- the error details on the stack, carry out the house keeping and
- then retrieve the error information and exit.
-
- No doubt there are other points which may require further
- clarification, but I hope that readers will be encouraged to have
- a go at writing in ARM assembler. I find it a lot easier than
- writing in 6502 assembler and you are really spoilt with such a
- wealth of OS calls to choose from. May I also commend the
- technique of trying out your ideas in BASIC first. With the
- complex logic of this current example I am sure that I would have
- floundered if I had gone straight into assembler.
-
- To use the programs:
-
- First CHAIN"M7generate". This program will draw a mode 7 screen
- and save it as Rm7saveS. You may find the screensave routine
- useful for use in other programs.
-
- Secondly type in and CHAIN WAITsrc which will produce the dummy
- printdump *WAIT.
-
- The BASIC programs can be tested by CHAINing either ARCSIMUL8 or
- ARCSIMCOL (which is produced by amending ARCSIMUL8 as shown in
- the table below). When prompted for a filename enter m7save. The
- program will pause at various stages until you press <space>. If
- you wish to produce a real print dump, then amend the programs as
- detailed in the REM statements.
-
- To use the machine code transients, CHAIN "M7M4src" from the
- program disc to produce M7M4. You can then CHAIN the progam
- TESTBED to test this. Once again, enter the filename m7save and
- the program will pause at each stage until you press <space>.
- M7M9src can also be tested using the TESTBED program with the
- dump line suitably altered.
-
- On the program disc, in the ModeConv directory, you will find:
-
- ARCSIMUL8 Mode 7 to Mode 4 converter
-
- ARCSIMCOL Mode 7 to Mode 9 converter (note that this is produced
- by making simple changes to ARCSIMUL8)
-
- M7M4src Source code for *M7M4 Mode 7 to Mode 4 converter
-
- M7M4 Transient utility. Mode 7 to Mode 4 converter
-
- M7M9src Source code for *M7M9 Mode 7 to Mode 9 converter (note
- that this is produced by making simple changes to M7M4src)
-
- M7M9 Transient utility. Mode 7 to Mode 4 converter
-
- WAIT Dummy dump utility: *WAIT waits for a key press
-
- WAITsrc Source code for *WAIT
-
- TESTBED A program to test the operation of M7M4 and M7M9
-
- M7generate A program to generate and save a specimen mode 7
- screen
-
- M7save The saved Mode 7 screen
-
-
-